// Copyright (C) 2024 Kumo inc.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#include <iostream>
#include <string>

#include <rothar/pegtl.hpp>



namespace hello
{
   // clang-format off
   struct prefix : rothar::string< 'H', 'e', 'l', 'l', 'o', ',', ' ' > {};
   struct name : rothar::plus< rothar::alpha > {};
   struct grammar : rothar::seq< prefix, name, rothar::one< '!' >, rothar::eof > {};
   // clang-format on

   template< typename Rule >
   struct action
   {};

   template<>
   struct action< name >
   {
      template< typename ActionInput >
      static void apply( const ActionInput& in, std::string& v )
      {
         v = in.string();
      }
   };

}  // namespace hello

int main( int argc, char** argv )  // NOLINT(bugprone-exception-escape)
{
   if( argc > 1 ) {
      std::string name;

      rothar::argv_input in( argv, 1 );
      if( rothar::parse< hello::grammar, hello::action >( in, name ) ) {
         std::cout << "Good bye, " << name << "!" << std::endl;
      }
      else {
         std::cerr << "I don't understand." << std::endl;
      }
   }
}
